package com.lwj.liwanjia.wxapi;


import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.lwj.liwanjia.R;
import com.lwj.liwanjia.utils.RxBus;
import com.lwj.liwanjia.view.activity.indent.IndentActivity;
import com.lwj.liwanjia.view.activity.indent.PayCompleteActivity;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import constants.Constants;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {

    private static final String TAG = "MicroMsg.SDKSample.WXPayEntryActivity";

    private IWXAPI api;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        api = WXAPIFactory.createWXAPI(this, Constants.APP_ID);
        api.handleIntent(getIntent(), this);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        api.handleIntent(intent, this);
    }

    @Override
    public void onReq(BaseReq req) {
    }

    @Override
    public void onResp(BaseResp resp) {
        switch (resp.errCode) {
            case 0:
                Toast.makeText(this, "支付成功", Toast.LENGTH_SHORT).show();
                RxBus.getInstance().post("支付完成");
                break;
            case -1://支付异常
                Toast.makeText(this, "支付失败", Toast.LENGTH_SHORT).show();
                RxBus.getInstance().post("支付失败");
                break;
            case -2://用户取消支付
                Toast.makeText(this, "支付取消", Toast.LENGTH_SHORT).show();
                RxBus.getInstance().post("支付取消");
                break;
        }
        finish();
    }
}